local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_PlayerComponent(),script.Parent.Name);
local ShowGui = _G.ClientOHOH.load.UIManager():CreateUI("ShowGui",require(script.ShowGui))
local fireworkEffect=ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.Effect.firework")
local firePos = {}
local Podium = workspace:WaitForChild("Podium")
local Client_AudioManager = ClientOHOH.load.Client_AudioManager();
local soundId = "firework"
function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);	
    self.player=self.parent
	
	self:AddConnect()
end

function M.AddConnect(self)
	_G.client.TimeOutEvent:Connect(function()
        print("超时")
        self:AddProcess(function()
			ShowGui:Show()
			self:Wait(0.9)
			ShowGui:Hide()
		end)
    end)

	 _G.client.GameStateChangeEvent:Connect(function(state)
        if state==2 then
			self:GetFirePos()
			if #game.Workspace:GetAttribute("ReachPlayers") ~= 0 then
				self:AddProcess(function()
					self:Wait(1)
					self:PlayFireWorkEffect()
				end)
			end
        end
    end)
end


function M.PlayFireWorkEffect(self)
	for i = 1, 3, 1 do
		local e=fireworkEffect:Clone()
		e.Parent = workspace
		e.CFrame = firePos[i]
		e.Transparency = 1
		local animation = require(e.Animation)
		self:AddProcess(function()
			animation.play()
			Client_AudioManager:PlayToInst(soundId,e)
			self:Wait(1)
			animation.play()
			Client_AudioManager:PlayToInst(soundId,e)
			self:Wait(2)
			e:Destroy()
		end)
	end
end

--初始化播放烟花位置
function M.GetFirePos(self)
	for index = 1, 3, 1 do
		firePos[index] =  Podium.ctrl["firework"..index].value.WorldCFrame
	end
end

function M.dtor(self)
	M.super.dtor(self);
end;

return M